//
//  WJ_Follow_VC.m
//  WJBSApp
//
//  Created by dllo on 16/7/14.
//  Copyright © 2016年 王景伟. All rights reserved.
//
// 这个要重写  // LastView 和 
#import "WJ_Follow_VC.h"
#import "WJ_TJ_ViewController.h"
#import "MBProgressHUD.h"
#import "WJLastModel.h"
#import "WJSearchCell.h"
#import "WJDataManager.h"
#import "WJLastViewController.h"


@interface WJ_Follow_VC ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,retain) WJBaseView *lable;

@property (nonatomic, strong) WJBaseTableView *tableView;

@property (nonatomic, strong) NSMutableArray *followArray;

@end

@implementation WJ_Follow_VC
static  NSString *const MeFollowCell = @"MeFollowCell";

-(void)dealloc
{
    [_tableView release];
    [_followArray release];
    self.tableView.delegate = nil;
    self.tableView.dataSource = nil;
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.followArray = [NSMutableArray array];
    
    [self createData];
    
    [self createConfig];
    
    [self createView];
    
    [self createTableView];
    
}

//每次进来都要执行
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.hidesBottomBarWhenPushed = NO;
    
     NSArray *array = [[WJDataManager shareFMDB] selectAll];
    if (array.count == 0) {
        
        self.tableView.hidden = YES;
        self.lable.hidden = NO;
        
    }else{
        
        self.tableView.hidden = NO;
        self.lable.hidden = YES;
        
        [self shuaxin];
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.tabBarController.hidesBottomBarWhenPushed = NO;
}

- (void)createConfig
{
    UIButton *button = [UIButton buttonWithTitle:nil frame:CGRectMake(0, 0, 30, 30) target:self action:@selector(leftAction)];
    [button setImage:[UIImage imageNamed:@"friendsRecommentIcon@3x"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"friendsRecommentIcon-click@3x"] forState:UIControlStateHighlighted];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    
 }


- (void)leftAction
{
    WJ_TJ_ViewController *tjView = [[WJ_TJ_ViewController alloc]init];
    [self.navigationController pushViewController:tjView animated:YES];
    [tjView release];
}

- (void)createView
{
    self.lable = [[WJBaseView alloc]initWithFrame:CGRectMake(20, 20, WIDTH - 40, WIDTH * 4 / 5)];
    [self.view addSubview:self.lable];
    [_lable release];
    
    WJBaseLable *textLable = [[WJBaseLable alloc]initWithFrame:CGRectMake(20, 70, WIDTH - 40 - 60, WIDTH * 2 / 5)];
    textLable.text = @"您还没有添加任何关注哦,快去看看推荐关注吧";
    textLable.numberOfLines = 0;
    textLable.layer.cornerRadius = 10;
    textLable.layer.masksToBounds = YES;
    [self.lable addSubview:textLable];
    [textLable release];
    
    WJBaseImageView *image = [[WJBaseImageView alloc]initWithFrame:CGRectMake(20, 0, 70, 70)];
    [self.lable addSubview:image];
    [image release];
    image.image = [UIImage imageNamed:@"header_cry_icon.png"];
    
    WJBaseButton *button = [WJBaseButton buttonWithTitle:@"去看看" frame:CGRectMake(WIDTH / 2 - 60, WIDTH * 4 / 5 - 70, 80, 40) target:self action:@selector(leftAction)];
    button.layer.borderWidth = 1;
    button.layer.cornerRadius = 2;
    button.layer.masksToBounds = YES;
    [self.lable addSubview:button];
    
}


- (void)createTableView
{
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"我的关注";
    
    self.tableView = [[WJBaseTableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 64 - 49) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = HEIGHT / 9;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[WJSearchCell class] forCellReuseIdentifier:MeFollowCell];
    [_tableView release];
}

- (void)createData
{
    // 这个数组里面有所有的名字和ID
    self.followArray = [[WJDataManager shareFMDB] selectAll];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.followArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WJSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:MeFollowCell];
    
    if (self.followArray.count != 0) {
        
    WJLastModel *model = self.followArray[indexPath.row];
    cell.model = model;
        
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WJLastViewController *last = [[WJLastViewController alloc]init];
    WJLastModel *model = self.followArray[indexPath.row];
    last.userID = model.id;
    last.userName = model.username;
    
    [self.navigationController pushViewController:last animated:YES];
    [last release];
}


- (void)shuaxin
{
    [self createData];
    [self.tableView reloadData];
}




































































- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
